package com.lagou.controller;

import com.lagou.dao.ResumeDao;
import com.lagou.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author : zhengyao3@郑瑶
 * @date : 2020/5/20 17:32
 * @Description: 登录控制类
 */
@RequestMapping("/login")
@Controller
public class LoginController {
    @Autowired
    private ResumeDao resumeDao;
    
    @RequestMapping("/login")
    public ModelAndView login(HttpServletRequest request, HttpServletResponse response, String userName,
                              String passWord){
        ModelAndView modelAndView = new ModelAndView();
        // addObject 其实是向请求域中request.setAttribute("date",date);
       
       
        if ("admin".equals(userName) && "admin".equals(passWord)) {
            // 视图信息(封装跳转的页面信息) 逻辑视图名
            List<Resume> resumeList = resumeDao.findAll();
            modelAndView.addObject("list", resumeList);
            modelAndView.setViewName("list");
            HttpSession session = request.getSession();
            session.setAttribute(userName, "success");
            session.setAttribute("username", userName);
            return modelAndView;
        }
        modelAndView.setViewName("error");
        modelAndView.addObject("msg","登录失败!账号密码不正确,请重新登录!");
        return modelAndView;
    }
}
